﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using InstantNaukriDAL;
public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        try
        {
            lblMsg.Text = "";
            clsUserLoginDAL objclsUserLoginDAL = new clsUserLoginDAL();
            IN_TB_USER objIN_TB_USER = new IN_TB_USER();
            objIN_TB_USER = objclsUserLoginDAL.GetUserByUserNamePassword(txtUserName.Text.Trim(), txtPassword.Text.Trim());
            if (objIN_TB_USER != null)
            {
                string roleid="";
                switch (objIN_TB_USER.ROLEID)
                {
                    case 1:
                        Session["UserId"] = objIN_TB_USER.ID.ToString();
                         roleid= clsEncryptionDecryption.Encrypt("1");
                        Session["RoleId"] = roleid;
                        clsEmployerDAL objclsEmployerDAL = new clsEmployerDAL();
                        Response.Redirect("CityMaster.aspx?roleid=" + roleid);
                        break;
                    case 2:
                        break;
                    case 3:
                        Session["UserId"] = objIN_TB_USER.ID.ToString();
                        roleid = clsEncryptionDecryption.Encrypt("3");
                        Session["roleid"] = roleid;
                        objclsEmployerDAL = new clsEmployerDAL();
                        IN_TB_EMPLOYER_MST objIN_TB_EMPLOYER_MST = new IN_TB_EMPLOYER_MST();
                        objIN_TB_EMPLOYER_MST = objclsEmployerDAL.GetEmployerByUserId(objIN_TB_USER.ID);
                        if (objIN_TB_EMPLOYER_MST != null)
                        {
                            Session["EmployerId"] = objIN_TB_EMPLOYER_MST.ID.ToString();
                            Response.Redirect("PostJobs.aspx?roleid=" + roleid);
                        }
                        break;
                    case 4:
                        Session["UserId"] = objIN_TB_USER.ID.ToString();
                        roleid = clsEncryptionDecryption.Encrypt("4");
                        Session["roleid"] = roleid;
                        Response.Redirect("JobseekerPrieview.aspx?roleid=" + roleid);
                        break;
                    case 5:
                        Session["UserId"] = objIN_TB_USER.ID.ToString();
                        roleid = clsEncryptionDecryption.Encrypt("5");
                        Session["roleid"] = roleid;
                        clsBranchMasterDAL objclsBranchMasterDAL = new clsBranchMasterDAL();
                        IN_TB_BRANCH_MST objIN_TB_BRANCH_MST = new IN_TB_BRANCH_MST();
                        objIN_TB_BRANCH_MST = objclsBranchMasterDAL.GetBranchById(objIN_TB_USER.ID);
                        if (objIN_TB_BRANCH_MST != null)
                        {
                            Session["BranchID"] = objIN_TB_BRANCH_MST.ID.ToString();
                            Response.Redirect("PostJobs.aspx?roleid=" + roleid);
                        }
                        break;
                   
                    case 6:
                        break;
                    case default(int):
                        lblMsg.Text="Not an Authorized User.";
                            break;


                }
                
            }
            else
                lblMsg.Text = "Invalid UserName or Password !";
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}
